import random
answer = random.randint(0, 9)
count = 0
error_count = 0
while True:
    try:
        guess = int(input("请输入一个0~9之间的整数："))
        count += 1
        if guess > answer:
            print("遗憾，太大了！")
        elif guess < answer:
            print("遗憾，太小了！")
        else:
            print('预测{:.0f}次，您猜对了！'.format(count))
            break
    except ValueError:
        print("输入内容必须为整数！")
        error_count += 1
    if error_count >= 3:
        print("错误次数达到上限，程序已退出。")
        break